package collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionOperDemo {
    public static void main(String[] args) {
        Collection c1=new ArrayList();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);//c1:[java, c++, .net]

        Collection c2=new ArrayList();
        c2.add("android");
        c2.add("ios");
        c2.add("add");
        System.out.println("c2:"+c2);//c2:[android, ios, add]

        c1.addAll(c2);//将c2添加到c1中
        System.out.println("c1:"+c1);//c1:[java, c++, .net, android, ios, add]
        System.out.println("c2:"+c2);//c2:[android, ios, add]

        Collection c3=new ArrayList();
        c3.add("ios");
        c3.add("java");
        c3.add("php");

        boolean contains=c1.contains(c3);//判断c1是否包含c3中的所有元素
        System.out.println("是否包含:"+contains);//false

        //取交集:c1中只保留与c3的共有元素,而c3不变
        /*
        c1.retainAll(c3);
        System.out.println("c1:"+c1);//[java, ios]
        System.out.println("c3:"+c3);//[ios, java, php]
        */

        //删交集:将c1中与c3中共有的元素删除,而c3不变
        c1.removeAll(c3);
        System.out.println("c1:"+c1);//[c++, .net, android, add]
        System.out.println("c3:"+c3);//[ios, java, php]

    }
}
